﻿using System;
using System.Data;
using ContractManager.Common.Class;
using ContractManager.Common.FormBase;
using ContractManager.BLL.Business;

namespace ContractManager.Reports.TendersDocuments
{
    public partial class FrmBC14 : XtraFormBase
    {
        #region "Form Construction"
        public FrmBC14()
        {
            InitializeComponent();
        }
        #endregion

        #region "Private Method"

        private void BlankForm()
        {
            txtFromDate.EditValue = null;
            txtToDate.EditValue = null;
            txtMbId.EditValue = null;

            txtMbId.Properties.DataSource = ClsMemberBranch.SelectAll();
            txtMbId.Properties.DisplayMember = "MbName";
            txtMbId.Properties.ValueMember = "MbID";

            txtContract.Properties.DataSource = ClsContracts.GetLookupAll();
            txtContract.Properties.DisplayMember = "ConNo";
            txtContract.Properties.ValueMember = "ConId";
        }

        private void DoPerform()
        {
            string fileName = ReportName;
            string reportName = ClsVariable.GetReportFullPath(fileName);
            string mbId = String.Format("{0}",txtMbId.EditValue);
            int conId = txtContract.EditValue == null ? 0 : Convert.ToInt32(txtContract.EditValue);
            var report = new Stimulsoft.Report.StiReport();
            report.Load(reportName);

            ClsVariable.CreateWaitDialog(ClsVariable.StrCaption, "Vui lòng đợi...");
            ClsVariable.SetWaitDialogCaption("Đang nạp dữ liệu báo cáo...");

            DataTable dtReport = ClsReports.GetReportBc01(txtFromDate.DateTime, txtToDate.DateTime,
                                                          mbId, this.StoreProcedureName, conId);
            report.RegData(dtReport);
            report.Compile();
            ClsVariable.CloseWaitDialog();
            // In thông tin đơn vị, địa chỉ

            report["KyBaoCao"] = String.Format("Từ ngày {0} Đến ngày {1}", txtFromDate.DateTime.ToString("dd/MM/yyyy"),
                                               txtToDate.DateTime.ToString("dd/MM/yyyy"));

            report["DoiTuong"] = ClsVariable.IsSelectAllComboBoxEdit(txtMbId)
                ? "Tất cả"
                : String.Format("{0}", txtMbId.Text);


            ClsVariable.ApplyReportParam(report, ClsVariable.DtParam);
            report.Render(true);
            report.Show(this.MdiParent);
        }

        #endregion

        #region "Form Event"
        private void FrmBC14Load(object sender, EventArgs e)
        {
            BlankForm();
            if (!String.IsNullOrEmpty(FormXtraLayoutTemplate))
            {
                var fileLayout = ClsVariable.GetRestoreLayoutFullPath(FormXtraLayoutTemplate);
                layoutControl.RestoreLayoutFromXml(fileLayout);
            }
        }
        #endregion


        #region "Button Event"
        private void btnOk_Click(object sender, EventArgs e)
        {
            DoPerform();

        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        

    }
}
